//
//  HWFenleishitTuViewController.m
//  HWanGame
//
//  Created by 陈道斌 on 2020/9/27.
//  Copyright © 2020 Chendaobin. All rights reserved.
//

#import "HWFenleishitTuViewController.h"

#import "HWFenLeiYouXiCell.h"
#import "HWJinXuanCell.h"
#import "HWOnlinegameTableCell.h"
#import "HWFeiLeimodel.h"
#import "HWGameListModel.h" // 游戏列表
 
#import "HWFenleishitTuViewController.h"

#import "SDCycleScrollViewCdb.h"
#import "HWHomezhongyaodeCell.h"

#import "CLPlayerView.h"
#import "HWzuixingHomePageTableViewCell.h"


@interface HWFenleishitTuViewController ()<UITableViewDelegate,UITableViewDataSource,UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout,SDCycleScrollViewCdbDelegate>
@property(strong,nonatomic) SDCycleScrollViewCdb *cycleScrollView;
@property(strong,nonatomic) UITableView *mainaTableVie;
@property(strong,nonatomic) UICollectionView *maincollectionView;
@property(strong,nonatomic) NSMutableArray *feileiMuArr; // 左边分类
@property(strong,nonatomic) UITableView *otherTableVie;
@property(strong,nonatomic) NSIndexPath *selectedIndex;

@property(strong,nonatomic) NSMutableArray *dataMuArr;
@property(strong,nonatomic) NSString *p; //分页
@property(strong,nonatomic) NSString *max_p; // 最大分页
@property(strong,nonatomic) HWFeiLeimodel *selectedModel;
@property(strong,nonatomic) NSArray  *slideArr;


@property(strong,nonatomic) UITableView *jingxuanTableView;
@property (nonatomic, weak) CLPlayerView *playerView;
@property (nonatomic, assign) UITableViewCell *cell; // 记录的cell
@property(strong,nonatomic) UIView *jingxuanheaderView;





@end

@implementation HWFenleishitTuViewController




- (SDCycleScrollViewCdb *)cycleScrollView {
    if (!_cycleScrollView) {
        // 网络加载 --- 创建不带标题的图片轮播器
        _cycleScrollView = [SDCycleScrollViewCdb cycleScrollViewWithFrame:CGRectMake(10*CFLScaleValue, 5, kScreenW-78*CFLScaleValue-10*CFLScaleValue*2, 158) imageURLStringsGroup:nil];
        
        _cycleScrollView.infiniteLoop = YES;
        _cycleScrollView.delegate = self;
      //   _cycleScrollView.placeholderImage=[UIImage imageNamed:@"banner"];
        _cycleScrollView.pageControlStyle = SDCycleScrollViewCdbPageContolStyleNone;
        _cycleScrollView.autoScrollTimeInterval = 2.0; // 轮播时间间隔，默认1.0秒，可自定义
        _cycleScrollView.backgroundColor = [UIColor clearColor];
        _cycleScrollView.backgroundColor = [UIColor whiteColor];
        
        
    }
    return _cycleScrollView;
}


- (UITableView *)otherTableVie {
    
    if (_otherTableVie == nil) {
        _otherTableVie = [[UITableView alloc]initWithFrame:CGRectMake(78*CFLScaleValue, 0,kScreenW-78*CFLScaleValue, kScreenH-TabBarHeight-NavBarHeight-44) style:UITableViewStylePlain];
        _otherTableVie.delegate = self;
        _otherTableVie.dataSource = self;
        _otherTableVie.tag = 100;
        _otherTableVie.hidden = YES;
        _otherTableVie.separatorStyle = UITableViewCellSeparatorStyleNone;
        _otherTableVie.backgroundColor = [UIColor whiteColor];
        
        
    }
    
    return  _otherTableVie;
    
    
}

-(UITableView *)mainaTableVie {
    
    if (_mainaTableVie == nil
        ) {
        
        _mainaTableVie = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 78*CFLScaleValue, kScreenH-TabBarHeight-NavBarHeight-44) style:UITableViewStylePlain];
        _mainaTableVie.delegate = self;
        _mainaTableVie.dataSource = self;
        _mainaTableVie.separatorStyle = UITableViewCellSeparatorStyleNone;
        _mainaTableVie.backgroundColor = [UIColor whiteColor];
        _mainaTableVie.backgroundColor = [UIColor whiteColor];
        
        
        
    }
    return   _mainaTableVie ;
    
}

- (UITableView *)jingxuanTableView {
    
    if (_jingxuanTableView == nil) {
        
        _jingxuanTableView = [[UITableView alloc]initWithFrame:CGRectMake(78*CFLScaleValue, 0,kScreenW-78*CFLScaleValue, kScreenH-TabBarHeight-NavBarHeight-44) style:UITableViewStylePlain];
        _jingxuanTableView.delegate = self;
        _jingxuanTableView.dataSource = self;
        _jingxuanTableView.tag = 200;
       
        _jingxuanTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _jingxuanTableView.backgroundColor = [UIColor whiteColor];
        
        
    }
    
    return   _jingxuanTableView ;
    
    
    
}





- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor yellowColor];
    
    
    
    
    
    //设置长用的属性
    [self setupshuxing];
    // 添加UI试图
    [self setupUI];
    //添加控件
    [self addControlsview];
    //  添加OtheView
    [self addOthetaview];
    //添加刷新控件
    [self addrefreshControl];
    
    
    //添加精选
    [self addjingxuanView];
    
    if ([self.judgeStr isEqualToString:@"1"]) {
        [self recalculateCoordinates];
        
    }
    
    //查询分类
    [self chaxunqueryClassification];
    
    
}

// 添加精选
- (void)addjingxuanView {
    
    
    
    [self.view addSubview:self.jingxuanTableView];
    
    
  



}
// 刷新tabelView头部
- (void)shuxingtabletoubu {
    
    self.jingxuanheaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenW-78*CFLScaleValue, 5+158+20+20)];
    self.cycleScrollView.localizationImageNamesGroup = @[[UIImage imageNamed:@"banner"],[UIImage imageNamed:@"banner"],[UIImage imageNamed:@"banner"]];
    //轮播图
    //  self.cycleScrollView.imageURLStringsGroup = imagesURLStrings;
    //轮播图
     [self.jingxuanheaderView addSubview:self.cycleScrollView];
    
    
    NSMutableArray *arr = [[NSMutableArray alloc]init];
    
    NSMutableArray *bianliMuArr = [self.slideArr  mutableCopy];
    

    for (int i = 0 ; i < self.slideArr.count; i++) {
        NSDictionary *dic = self.slideArr[i];
        NSString  *game_name  =  [NSString stringWithFormat:@"%@",dic[@"game_name"]];
        if ([game_name isEqualToString:@""]) {
            [bianliMuArr removeObjectAtIndex:i];
            break;
            
        }
        
        NSString *iamgeStr = [NSString stringWithFormat:@"%@",dic[@"image"]];
        [arr addObject:iamgeStr];
 
    }

     self.cycleScrollView.isTooltiao = YES;
 //     self.cycleScrollView.slideArr = self.slideArr;
     self.cycleScrollView.slideArr = bianliMuArr;
     self.cycleScrollView.imageURLStringsGroup = arr;
     self.cycleScrollView.panduanStr = @"1";
    

     UILabel *selectLabel = [[UILabel alloc]initWithFrame:(CGRect)CGRectMake(5, 158+20, 90, 20)];
     selectLabel.font = [UIFont systemFontOfSize:15];
     selectLabel.textColor = RGB(68, 68, 68);
     selectLabel.text = @"精选推荐";
     selectLabel.text  = [HWjianzhiduiObject keylocalization:@"精选推荐"];

     [  self.jingxuanheaderView addSubview:selectLabel];
      
    
    self.jingxuanTableView.tableHeaderView = self.jingxuanheaderView;
    
    
    
    
       
    
}


- (void)addrefreshControl {
    
   self.maincollectionView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(underRefresh)];
  //  [self.mainaTableVie.mj_header beginRefreshing];
   //  self.maincollectionView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(onRefresh)];
    
    self.otherTableVie.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(underRefresh)];
     self.otherTableVie.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(onRefresh)];
    
    self.jingxuanTableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(underRefresh)];
 //    self.jingxuanTableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(onRefresh)];
    [self.jingxuanTableView.mj_header beginRefreshing];
}

- (void)viewDidDisappear:(BOOL)animated {
    
    
    [_playerView destroyPlayer];
    _cell = nil;
    
}



//  关闭播放
- (void)closeplayView {
    
    [_playerView destroyPlayer];
     _cell = nil;
       
    
}





#pragma  mark ------
//下拉刷新
- (void)underRefresh {
    DLog(@"精选");
    
    
    HWFeiLeimodel *model =  self.selectedModel;
    if (model == nil) {
        [self.maincollectionView.mj_header endRefreshing];
        [self.maincollectionView.mj_footer endRefreshing];
        [self.otherTableVie.mj_header endRefreshing];
        [self.otherTableVie.mj_footer endRefreshing];
        [self.jingxuanTableView.mj_header endRefreshing];
        [self.jingxuanTableView.mj_footer endRefreshing];
        return;
    }
    self.p  = @"1";
  //   12
    self.dataMuArr = [[NSMutableArray alloc]init];
    
//    NSDictionary *parametes = @{
//                                @"ct" :  @"app",
//                                @"ac" : @"fenlei_game",
//                                @"type": model.id,
//                                @"p"  : self.p,
//                                @"ios" : @"1"
//                                };
    
    
    
    
    NSDictionary *parametes = @{
                                    @"ct" :  @"app",
                                    @"ac" : @"fenlei_game",
                                    @"fenlei_id":model.id,
                                    @"system_type":@"0",
                                    @"type":model.id,
                                    @"p"  :@"1",
                                    @"member_id":[HWLocallyStoredData getCode],
                                    @"ios" : @"1",
                                    
                                    };
    
    
  
    
    [HWWebUtils do3GetWithParameters:parametes progress:nil success:^(id response) {
        
        
        NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
       
        [self.maincollectionView.mj_header endRefreshing];
        [self.maincollectionView.mj_footer endRefreshing];
        [self.otherTableVie.mj_header endRefreshing];
        [self.otherTableVie.mj_footer endRefreshing];
        [self.jingxuanTableView.mj_header endRefreshing];
        [self.jingxuanTableView.mj_footer endRefreshing];
        
        
        if ([codeStr intValue] == 1) {
          //  [MBProgressHUD  showError:@"加载成功"];
                NSArray *arr = response[@"data"][@"game"][@"list"];
            
//
//            if (arr.count > 0 ) {
//
//                self.dataMuArr = [HWGameListModel mj_objectArrayWithKeyValuesArray:arr];
//                                         self.slideArr =  response[@"data"][@"slide"];
//                                         self.p = [NSString stringWithFormat:@"%@",response[@"p"]];
//                                         self.max_p = [NSString stringWithFormat:@"%@",response[@"max_p"]];
//                                         [self.maincollectionView reloadData];
//                                         [self.otherTableVie reloadData];
//
//
//
//            } else {
//
//                self.dataMuArr = [HWGameListModel mj_objectArrayWithKeyValuesArray:response[@"data"]];
//                           self.slideArr =  response[@"data"][@"slide"];
//                           self.p = [NSString stringWithFormat:@"%@",response[@"p"]];
//                           self.max_p = [NSString stringWithFormat:@"%@",response[@"max_p"]];
//                           [self.maincollectionView reloadData];
//                           [self.otherTableVie reloadData];
//
//            }

                self.dataMuArr = [HWGameListModel mj_objectArrayWithKeyValuesArray:arr];
              //    self.slideArr =  response[@"data"][@"slide"];
                self.p = [NSString stringWithFormat:@"%@",response[@"data"][@"game"][@"p"]];
                self.max_p = [NSString stringWithFormat:@"%@",response[@"data"][@"game"][@"max_p"]];
                 self.maincollectionView.hidden = YES;
                [self.maincollectionView reloadData];
                [self.otherTableVie reloadData];
               [self.jingxuanTableView reloadData];

            [self shuxingtabletoubu];
            
          
            
            
        } else {
            
            self.dataMuArr = [[NSMutableArray alloc]init];
            
            [MBProgressHUD showError:response[@"message"]];
            
            
            
            [self.maincollectionView reloadData];
            [self.jingxuanTableView reloadData];
            [self.otherTableVie reloadData];
            
        }
        NSLog(@"%@",response);
        
        
    } failure:^(NSString *error) {
        
        [self.maincollectionView.mj_header endRefreshing];
        [self.maincollectionView.mj_footer endRefreshing];
        [self.otherTableVie.mj_header endRefreshing];
        [self.otherTableVie.mj_footer endRefreshing];
        [self.jingxuanTableView.mj_header endRefreshing];
        [self.jingxuanTableView.mj_footer endRefreshing];
        
        
        
        
    }];
    
    
    
    
    
    
    
}
//  上拉刷新

- (void)onRefresh {
    
    DLog(@"精选");
    
    
    if ([self.p intValue] > [self.max_p intValue]) {
        
       
        
        [self.maincollectionView.mj_header endRefreshing];
        [self.maincollectionView.mj_footer endRefreshing];
        [self.otherTableVie.mj_header endRefreshing];
        [self.otherTableVie.mj_footer endRefreshing];
        [self.jingxuanTableView.mj_header endRefreshing];
        [self.jingxuanTableView.mj_footer endRefreshing];

        [MBProgressHUD showError:@"暂时没有新数据"];
        
        
        return;
    }
      
    
    
    HWFeiLeimodel *model =  self.selectedModel;
    
    
    NSDictionary *parametes = @{
                                @"ct" :  @"app",
                                @"ac" : @"fenlei_game",
                                @"type": model.id,
                                @"p"  : self.p,
                                @"ios" : @"1"
                                };
    
    
    
    
    [HWWebUtils do3GetWithParameters:parametes progress:nil success:^(id response) {
        
        
        NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
        
        [self.maincollectionView.mj_header endRefreshing];
        [self.maincollectionView.mj_footer endRefreshing];
        [self.otherTableVie.mj_header endRefreshing];
        [self.otherTableVie.mj_footer endRefreshing];
        [self.jingxuanTableView.mj_header endRefreshing];
        [self.jingxuanTableView.mj_footer endRefreshing];
        
        if ([codeStr intValue] == 1) {
          //  [MBProgressHUD  showError:@"加载成功"];
            NSArray *arr = response[@"data"][@"game"][@"list"];
            if (arr.count > 0) {
                
                
              NSMutableArray  *muArr  = [HWGameListModel mj_objectArrayWithKeyValuesArray:arr];
                
                for (int i = 0; i < muArr.count; i++) {
                    
                    [self.dataMuArr addObject:muArr[i]];
                    
                }
                
              //  self.slideArr =  response[@"data"][@"game"][@"slide"];
                
//                self.p = [NSString stringWithFormat:@"%@",response[@"p"]];
//
//                self.max_p = [NSString stringWithFormat:@"%@",response[@"max_p"]];
                
                
                self.p = [NSString stringWithFormat:@"%@",response[@"data"][@"game"][@"p"]];
                
                self.max_p = [NSString stringWithFormat:@"%@",response[@"data"][@"game"][@"max_p"]];
            
                [self.maincollectionView reloadData];
                [self.otherTableVie reloadData];
                [self.jingxuanTableView reloadData];
                
            }
            
            
            
            
        } else {
            
            
            
        }
        NSLog(@"%@",response);
        
        
    } failure:^(NSString *error) {
        
        [self.maincollectionView.mj_header endRefreshing];
        [self.maincollectionView.mj_footer endRefreshing];
        [self.otherTableVie.mj_header endRefreshing];
        [self.otherTableVie.mj_footer endRefreshing];
        [self.jingxuanTableView.mj_header endRefreshing];
        [self.jingxuanTableView.mj_footer endRefreshing];
        
    }];
    
    
    
}










// 查询分类
- (void)chaxunqueryClassification {
    
    
    
    
    NSDictionary *parametes = @{
                                   @"ct" :  @"app",
                                   @"ac" : @"fenlei",
                                    @"member_id":[HWLocallyStoredData getCode],
                                   @"ios" : @"1"
                                   };
       
     //  [MBProgressHUD show:<#(NSString *)#>]
     //  [MBProgressHUD showMessage:@"正在加载" toView:nil];
       
       
       [HWWebUtils do3GetWithParameters:parametes progress:nil success:^(id response) {
           
         
           NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
           [MBProgressHUD hideHUD];
           
           
           if ([codeStr intValue] == 1) {
            //   [MBProgressHUD  showError:@"加载成功"];
               //  HWFeiLeimodel
               NSArray *arr =  response[@"data"];
               self.feileiMuArr = [HWFeiLeimodel mj_objectArrayWithKeyValuesArray:arr];
               [self.mainaTableVie reloadData];
               
               if (self.feileiMuArr.count > 0) {
                   HWFeiLeimodel *model = self.feileiMuArr[0];
                   self.dataMuArr = [[NSMutableArray alloc]init];
                   self.selectedModel  = model;
                   
                   [self fenleiyouxiID:model.id];
                   
                   
               }
              
               
       

           } else {
               
                [MBProgressHUD  showError:@"加载失败"];
               
           }
           NSLog(@"%@",response);
           
           
       } failure:^(NSString *error) {
         
           [MBProgressHUD  showError:@"加载失败"];
           
           
               
       }];
       
    
    
    
    
    
    
    
//    NSDictionary *parametes = @{
//                                @"ct" :  @"app",
//                                @"ac" : @"fenlei",
//                                @"ios" : @"1"
//                                };
//
//  //  [MBProgressHUD show:<#(NSString *)#>]
//  //  [MBProgressHUD showMessage:@"正在加载" toView:nil];
//
//
//    [HWWebUtils doGetWithParameters:parametes progress:nil success:^(id response) {
//
//
//        NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
//        [MBProgressHUD hideHUD];
//
//
//        if ([codeStr intValue] == 1) {
//         //   [MBProgressHUD  showError:@"加载成功"];
//            //  HWFeiLeimodel
//            NSArray *arr =  response[@"data"];
//            self.feileiMuArr = [HWFeiLeimodel mj_objectArrayWithKeyValuesArray:arr];
//            [self.mainaTableVie reloadData];
//
//            if (self.feileiMuArr.count > 0) {
//                HWFeiLeimodel *model = self.feileiMuArr[0];
//                self.dataMuArr = [[NSMutableArray alloc]init];
//                self.selectedModel  = model;
//
//                [self fenleiyouxiID:model.id];
//
//
//            }
//
//
//
//
//        } else {
//
//             [MBProgressHUD  showError:@"加载失败"];
//
//        }
//        NSLog(@"%@",response);
//
//
//    } failure:^(NSString *error) {
//
//        [MBProgressHUD  showError:@"加载失败"];
//
//
//
//    }];
    
    
    
    
}

//查询分类详情
- (void)fenleiyouxiID:(NSString *)IdStr {
    
    
    [MBProgressHUD showMessage:@"正在加载" toView:nil];
    
    NSDictionary *parametes = @{
                                  @"ct" :  @"app",
                                  @"ac" : @"fenlei_game",
                                  @"fenlei_id":IdStr,
                                  @"system_type":@"0",
                                  @"type":@"0",
                                  @"p"  :@"1",
                                  @"member_id":[HWLocallyStoredData getCode],
                                  @"ios" : @"1"
                                  };
      
      [HWWebUtils do3GetWithParameters:parametes progress:nil success:^(id response) {
          
          
          NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
          [MBProgressHUD hideHUD];
          
          
          if ([codeStr intValue] == 1) {
              [MBProgressHUD  showError:@"加载成功"];
              NSArray *arr = response[@"data"][@"game"][@"list"];
              if (arr.count > 0) {
                  
                  
                  self.dataMuArr = [HWGameListModel mj_objectArrayWithKeyValuesArray:arr];
                  
                  self.p = [NSString stringWithFormat:@"%@",response[@"p"]];
                  
                  self.max_p = [NSString stringWithFormat:@"%@",response[@"max_p"]];
                  
                 //  self.slideArr =  response[@"data"][@"slide"];
                  [self.mainaTableVie.mj_header beginRefreshing];
                
                  [self.maincollectionView reloadData];
                  
                  [self shuxingtabletoubu];
                  
                  
                  
                  
              }
              
              self.slideArr =  response[@"data"][@"slide"];
            
          // HWGameListModel
              
          //   self.latestMutaBleArr  = [HWGameListModel mj_objectArrayWithKeyValuesArray:latestArr];
              
              
              
          } else {
              
               [MBProgressHUD  showError:@"加载失败"];
              
          }
          NSLog(@"%@",response);
          
          
      } failure:^(NSString *error) {
          
          [MBProgressHUD  showError:@"加载失败"];
          
      }];
    
    
    
    
    
//    NSDictionary *parametes = @{
//                                @"ct" :  @"app",
//                                @"ac" : @"fenlei_game",
//                                @"type": IdStr,
//                                @"p"  :@"1",
//                                @"ios" : @"1"
//                                };
//
//    [HWWebUtils doGetWithParameters:parametes progress:nil success:^(id response) {
//
//
//        NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
//        [MBProgressHUD hideHUD];
//
//
//        if ([codeStr intValue] == 1) {
//            [MBProgressHUD  showError:@"加载成功"];
//            NSArray *arr = response[@"data"];
//            if (arr.count > 0) {
//
//
//                self.dataMuArr = [HWGameListModel mj_objectArrayWithKeyValuesArray:arr];
//
//                self.p = [NSString stringWithFormat:@"%@",response[@"p"]];
//
//                self.max_p = [NSString stringWithFormat:@"%@",response[@"max_p"]];
//
//
//
//
//                [self.maincollectionView reloadData];
//            }
//
//        // HWGameListModel
//
//        //   self.latestMutaBleArr  = [HWGameListModel mj_objectArrayWithKeyValuesArray:latestArr];
//
//
//
//        } else {
//
//             [MBProgressHUD  showError:@"加载失败"];
//
//        }
//        NSLog(@"%@",response);
//
//
//    } failure:^(NSString *error) {
//
//        [MBProgressHUD  showError:@"加载失败"];
//
//    }];
//
    
    
    
    
}





// 重新做坐标
- (void)recalculateCoordinates {
    self.otherTableVie.frame = CGRectMake(78*CFLScaleValue, 0,kScreenW-78*CFLScaleValue, kScreenH);
    self.mainaTableVie.frame = CGRectMake(0, 0, 78*CFLScaleValue, kScreenH);
    self.maincollectionView.frame  =  CGRectMake(78*CFLScaleValue, 0, kScreenW-78*CFLScaleValue, kScreenH);
    
}

//  添加OtheyTabview
- (void)addOthetaview {
    
    
    [self.view addSubview:self.otherTableVie];
}

- (void)setupshuxing {
    
    self.navigationItem.title = @"游戏大厅";
   // self.feileiArr = @[@"精选",@"卡牌",@"竞技",@"生存",@"休闲",@"仙侠",@"动作",@"放置",@"角色",@"卡牌",@"竞技",@"生存",@"休闲",@"仙侠",@"动作",@"放置",@"角色"];
    
    
    
}

//设置UI
- (void)setupUI {
    
     [self.view addSubview:self.mainaTableVie];
    
}

#pragma  mark -----  添加控件
- (void)addControlsview {
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.minimumLineSpacing = 10;
    
    CGFloat juanju  = (kScreenW - 10*CFLScaleValue*2-52*CFLScaleValue*3-78*CFLScaleValue)/3;
    layout.minimumInteritemSpacing = juanju-1;
    
    
     layout.minimumInteritemSpacing = 10;
    layout.headerReferenceSize = CGSizeMake(kScreenW, 158+20+20+10);  //设置headerView大小
    self.maincollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(78*CFLScaleValue, 0, kScreenW-78*CFLScaleValue, kScreenH-TabBarHeight-NavBarHeight-44) collectionViewLayout:layout];
    // self.maincollectionView.showsHorizontalScrollIndicator = NO;
    self.maincollectionView.delegate = self;
    self.maincollectionView.dataSource = self;
    self.maincollectionView.alwaysBounceVertical = YES;
    self.maincollectionView.backgroundColor = [UIColor whiteColor];
   // self.maincollectionView.contentInset = UIEdgeInsetsMake(0, 15, 0, 15);
    self.maincollectionView.contentInset = UIEdgeInsetsMake(0, 15*CFLScaleValue, 0, 15*CFLScaleValue);
    [self.maincollectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView"];  //  一定要设置
  //  [self.maincollectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cellID"];
    [self.maincollectionView  registerNib:[UINib nibWithNibName:@"HWJinXuanCell" bundle:nil] forCellWithReuseIdentifier:@"cellID"];
    self.maincollectionView.userInteractionEnabled = YES;
    self.maincollectionView.hidden = YES;
    [self.view  addSubview:self.maincollectionView];
    
    
    
}




- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    
    if (tableView.tag == 100) {
         return   self.dataMuArr.count;
    } else if (tableView.tag == 200) {
        
        return self.dataMuArr.count;
        
        
    }
    
    
    
    return   self.feileiMuArr.count;
    
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (tableView.tag == 100 ) {
        
//        static NSString *cellID = @"cellIDOnlinegame";
//
//        HWOnlinegameTableCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
//        if (!cell ) {
//            cell = [[NSBundle mainBundle]loadNibNamed:@"HWOnlinegameTableCell" owner:nil options:nil].lastObject;
//
//        }
//        cell.selectionStyle = UITableViewCellSelectionStyleNone;
//        cell.sizeGameLabel.hidden = YES;
//        cell.penfenImageView.hidden = NO;
//        cell.penfenLabel.hidden = NO;
//        cell.fenleimodel = self.dataMuArr[indexPath.row];
//        cell.backgroundColor = [UIColor whiteColor];
//        return  cell;
//
        
        static NSString *cellID = @"cellID1";
           
           HWHomezhongyaodeCell  *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
           
           
           if (!cell) {
               cell = [[NSBundle mainBundle]loadNibNamed:@"HWHomezhongyaodeCell" owner:nil options:nil].firstObject;
               
           }
            HWGameListModel  *model = self.dataMuArr[indexPath.row];
           cell.youxiModel = model;
           cell.xiantiaoView.hidden = YES;
        
         cell.newbeijingiamgeView.hidden = YES;
         cell.beijingshituView.backgroundColor = [UIColor whiteColor];
                      
         cell.jianjutupian.constant = 0;
        cell.topjianju.constant = 31;
        
        cell.contentView.backgroundColor  = RGB(255, 255, 255);
        
        return  cell;
        
           
          // 精选推荐
           
//           if (indexPath.section  == 0 ) {
//
//               if (indexPath.row == 0 ) {
//
//                      cell.newbeijingiamgeView.hidden = NO;
//
//                      cell.xiantiaoView.hidden = NO;
//                     //  cell.xiantiaoView.hidden = YES;
//                      cell.beijingshituView.backgroundColor = [UIColor clearColor];
//                      [cell.beijingtupianIangeview sd_setImageWithURL:[NSURL URLWithString:model.image] placeholderImage:nil];
//
//                      cell.jianjutupian.constant = 20;
//                      cell.topjianju.constant = 46;
//
//
//
//                  } else {
//
//                        cell.newbeijingiamgeView.hidden = YES;
//                       cell.beijingshituView.backgroundColor = [UIColor whiteColor];
//
//                       cell.jianjutupian.constant = 0;
//                        cell.topjianju.constant = 31;
//
//                  }
//
//           } else {
//
//               cell.newbeijingiamgeView.hidden = YES;
//               cell.beijingshituView.backgroundColor = [UIColor whiteColor];
//
//               cell.jianjutupian.constant = 0;
//               cell.topjianju.constant = 31;
//
//           }
//
//
        
        
        
        
    }else if (tableView.tag == 200 ) {
        
        
        static NSString *cellID = @"cellIDtext";
        HWzuixingHomePageTableViewCell  *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
                 
          if (!cell) {
                  
              cell =  [[NSBundle mainBundle]loadNibNamed:@"HWzuixingHomePageTableViewCell" owner:nil options:nil].lastObject;
           }
        
        
           cell.selectionStyle =  UITableViewCellSelectionStyleNone;
           cell.backgroundColor = [UIColor whiteColor];
       
        cell.diyigezuobianconte.constant = 10 ;
        cell.diergezuobianconte.constant = 10 ;
        cell.disangezuobianconte.constant = 10 ;
      //     NSArray *arr = self.dataMuArr[2];
        
        HWGameListModel *datamodel1 =  self.dataMuArr[indexPath.row];
      
        //  HWGameListModel  *model = datamodel1.list[indexPath.row];
         cell.fenleiModel = datamodel1;
         cell.biaoqilabel.text = [NSString stringWithFormat:@"%@",@"爆"];
         cell.biaoqilabel.hidden = YES;
         cell.qipaoImageView.hidden = YES;
        
        UIImageView *imageview = [[UIImageView alloc] initWithFrame:CGRectMake(10, 64+12+12, kScreenW -20 -78*CFLScaleValue, 140)];
        [cell.contentView addSubview:imageview];
        imageview.userInteractionEnabled = YES;
        imageview.layer.cornerRadius = 5;
        imageview.layer.masksToBounds= YES;
        imageview.contentMode  = UIViewContentModeScaleAspectFill;
        [imageview sd_setImageWithURL:[NSURL URLWithString:datamodel1.video_img] placeholderImage:nil];
        [cell.contentView addSubview:imageview];
    
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageviewTap:)];
        [imageview addGestureRecognizer:tap];
        
        
     
        // bofangannniu
       
        UIImageView *bofanimageView = [[UIImageView alloc]initWithFrame:CGRectMake((kScreenW -20 -78*CFLScaleValue-32)/2, (140 -32)/2, 32, 32)];
        bofanimageView.image = [UIImage imageNamed:@"bofananniicoshitu"];
        [imageview addSubview:bofanimageView];
        
        
        
        if ([datamodel1.video_url isEqualToString:@""]) {
            
            
            imageview.userInteractionEnabled = NO;
            bofanimageView.hidden = YES;
            
        } else {
            
            imageview.userInteractionEnabled = YES;
            bofanimageView.hidden = NO;
            
        }
        
                
        
        return  cell;
        
       
       
        
    }else {
        
        
        static NSString *cellID = @"cellID";
        HWFenLeiYouXiCell *cell =  [tableView dequeueReusableCellWithIdentifier:cellID];
        if (!cell) {
            cell =    [[NSBundle mainBundle]loadNibNamed:@"HWFenLeiYouXiCell" owner:nil options:nil].lastObject;
        }
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
         cell.backgroundColor = [UIColor whiteColor];
        HWFeiLeimodel *mode = self.feileiMuArr[indexPath.row];
        
        cell.nameLabel.text =  mode.name;
        cell.backgroundColor = [UIColor whiteColor];
        
        if (self.selectedIndex != nil) {
            if (self.selectedIndex == indexPath) {
                
                cell.xuanzhongview.hidden = NO;
                cell.nameLabel.backgroundColor = [UIColor whiteColor];
            } else {
                
                cell.xuanzhongview.hidden = YES;
                cell.nameLabel.backgroundColor = RGB(247, 247, 247);
            }
            
            
        } else {
            
             if (indexPath.row == 0) {
                    cell.xuanzhongview.hidden = NO;
                    cell.nameLabel.backgroundColor = [UIColor whiteColor];
                    self.selectedIndex = indexPath;
            
            
            
                } else {
                    cell.xuanzhongview.hidden = YES;
                    cell.nameLabel.backgroundColor = RGB(247, 247, 247);
            
                }
            
            
            
            
        }
       
        
        
 
        return  cell;
        
    }
    
  
    
}


- (void)imageviewTap:(UITapGestureRecognizer *)sende {
    
    
  
    
    UIView *view = [sende view] ;
    NSLog(@"123 %@",[[view superview] superview] );
    
    
    NSLog(@"11111");
    
   //  [NSIndexPath indexPathForItem:0 inSection:0]
    
 //    return;
    
    
    
    HWzuixingHomePageTableViewCell *cell =  (HWzuixingHomePageTableViewCell *)[[view superview] superview];
  
    _cell = cell;
    
    
    
    NSIndexPath *indexPath = [self.jingxuanTableView indexPathForCell:cell];
    
    HWGameListModel *datamodel1 =  self.dataMuArr[indexPath.row];
    
    
    [_playerView destroyPlayer];
    CLPlayerView *playerView = [[CLPlayerView alloc] initWithFrame:CGRectMake(10, 64+12+12, kScreenW -20 -78*CFLScaleValue, 140)];
    _playerView = playerView;
    [cell.contentView addSubview:_playerView];
    //视频地址
    _playerView.url = [NSURL URLWithString:datamodel1.video_url];

    [_playerView updateWithConfigure:^(CLPlayerViewConfigure *configure) {
        configure.topToolBarHiddenType = TopToolBarHiddenSmall;
        configure.autoRotate = NO;
       //  configure.smallGestureControl = YES;
    }];
    //播放
    [_playerView playVideo];
    //返回按钮点击事件回调
    [_playerView backButton:^(UIButton *button) {
        NSLog(@"返回按钮被点击");
    }];
    //播放完成回调
    [_playerView endPlay:^{
        //销毁播放器
        [self->_playerView destroyPlayer];
        self->_playerView = nil;
         self->_cell = nil;
        NSLog(@"播放完成");
    }];
    
    
    
}




#pragma  mark -------------- UITableViewDelegate


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    
    if (tableView.tag == 100 ) {
        
        return 78;
    }else if (tableView.tag == 200 ){
        
        
        return  64+12+12+140;
    }
    
    return  56;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    DLog(@"1234");
    
    
    if (tableView.tag == 100 ) {
        
        
        NSLog(@"daying");
        
        
        HWGameListModel *model = self.dataMuArr[indexPath.row];
        HWGameDetailController *gameDetails = [[HWGameDetailController alloc]init];
        gameDetails.gameId = model.id;
        
        [self.navigationController pushViewController:gameDetails animated:YES];
        
    } else if (tableView.tag == 200) {
        
        HWGameListModel *model = self.dataMuArr[indexPath.row];
        HWGameDetailController *gameDetails = [[HWGameDetailController alloc]init];
        gameDetails.gameId = model.id;
        [self.navigationController pushViewController:gameDetails animated:YES];
        
        
    }else {
        
        
        HWFenLeiYouXiCell *oldcell =  [tableView cellForRowAtIndexPath:self.selectedIndex];

        oldcell.xuanzhongview.hidden = YES;
        oldcell.nameLabel.backgroundColor = RGB(247, 247, 247);
        
        
        HWFenLeiYouXiCell *newcell =  [tableView cellForRowAtIndexPath:indexPath];
        newcell.xuanzhongview.hidden = NO;
        newcell.nameLabel.backgroundColor = [UIColor whiteColor];
        self.selectedIndex = indexPath;
        
        self.selectedModel = self.feileiMuArr[indexPath.row];
        
        
        
        if (indexPath.row == 0) {
            
            self.maincollectionView.hidden = NO;
            self.otherTableVie.hidden = YES;
            self.jingxuanTableView.hidden = NO;
            
            [self.maincollectionView.mj_header beginRefreshing];
            [self.jingxuanTableView.mj_header beginRefreshing];
            
            
        } else {
            
//            self.maincollectionView.hidden = YES;
//            self.otherTableVie.hidden = NO;
//
            self.maincollectionView.hidden = YES;
            self.otherTableVie.hidden = NO;
            self.jingxuanTableView.hidden = YES;
            
            
            [self.otherTableVie.mj_header beginRefreshing];
            
            
        }
        
        
        
    }
        
    //HWFenLeiYouXiCell self.tableView     self.selectedIndex
   
    
    
    
    
}








#pragma mark --------- UICollectionViewDelegate


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    
    
    return self.dataMuArr.count;
    
  
}


- (UICollectionReusableView *) collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView" forIndexPath:indexPath];
  //  headerView.backgroundColor = [UIColor redColor];
    
    
    
    
    
    return headerView ;
   self.cycleScrollView.localizationImageNamesGroup = @[[UIImage imageNamed:@"banner"],[UIImage imageNamed:@"banner"],[UIImage imageNamed:@"banner"]];
   //轮播图
   //  self.cycleScrollView.imageURLStringsGroup = imagesURLStrings;
   //轮播图
    [headerView addSubview:_cycleScrollView];
    
    


  NSMutableArray *arr = [[NSMutableArray alloc]init];
  
  for (int i = 0 ; i < self.slideArr.count; i++) {
      NSDictionary *dic = self.slideArr[i];
     
      NSString *iamgeStr = [NSString stringWithFormat:@"%@",dic[@"image"]];
      [arr addObject:iamgeStr];

  }
  
   self.cycleScrollView.isTooltiao = YES;
   self.cycleScrollView.slideArr = self.slideArr;
   self.cycleScrollView.imageURLStringsGroup = arr;
    self.cycleScrollView.panduanStr = @"1";
  
      
 
    
    
    UILabel *selectLabel = [[UILabel alloc]initWithFrame:(CGRect)CGRectMake(5, 158+20, 90, 20)];
    selectLabel.font = [UIFont systemFontOfSize:15];
    selectLabel.textColor = RGB(68, 68, 68);
    selectLabel.text = @"精选推荐";
    selectLabel.text  = [HWjianzhiduiObject keylocalization:@"精选推荐"];
    
    
    [headerView addSubview:selectLabel];
     
//    UIButton *butt = [UIButton createNormalButtonWithFrame:CGRectMake(kScreenW-78-24*2-38+8, imageView.bottom+13, 38, 13) Image:@"ba_r" Title:@"更多" font:13 imageSize:CGSizeMake(7, 11)];
//    [butt layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleRight imageTitleSpace:4];
//    butt.backgroundColor = [UIColor yellowColor];
//    [butt addTarget:self action:@selector(buttTap) forControlEvents:UIControlEventTouchUpInside];
//   // butt
//    [headerView addSubview:butt];
//
    return headerView;
}




- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    HWJinXuanCell *cell =  [collectionView dequeueReusableCellWithReuseIdentifier:@"cellID" forIndexPath:indexPath];
  //   cell.backgroundColor =[UIColor yellowColor];
    HWGameListModel *mode = self.dataMuArr[indexPath.row];
    
   //  cell.backgroundColor = [UIColor redColor];
    
    
    cell.model = mode;
    
    
    return cell;
    
    
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    return CGSizeMake(52*CFLScaleValue,12+52*CFLScaleValue+4);
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    DLog(@"12334");
    
    HWGameDetailController *gameDetails = [[HWGameDetailController alloc]init];
    
    HWGameListModel *mode = self.dataMuArr[indexPath.row];
    gameDetails.gameId = mode.id;
    
    
    [self.navigationController pushViewController:gameDetails animated:YES];
    
    
}



#pragma mark ------------   点击更多按钮

- (void)buttTap {
    
    
    DLog(@"145678778");
}

// 广告
- (void)imageViewTap1 {
    
    NSLog(@"12345");
    
    HWGameListModel *mode = self.dataMuArr[0];
    HWGameDetailController *gameDetails = [[HWGameDetailController alloc]init];
    gameDetails.gameId = mode.id;
    [self.navigationController pushViewController:gameDetails animated:YES];
    
    
}

- (void)imageViewTap2 {
    
       NSLog(@"67890");
    
    HWGameListModel *mode = self.dataMuArr[1];
    HWGameDetailController *gameDetails = [[HWGameDetailController alloc]init];
    gameDetails.gameId = mode.id;
    [self.navigationController pushViewController:gameDetails animated:YES];
    
    
}




#pragma mark --------------- 轮播图代理

- (void)cycleScrollView:(SDCycleScrollViewCdb *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
    
    
//    if (self.ADModelMuArr.count > 0) {
//
//        AdModel *model =   self.ADModelMuArr[index];
//
//
//          HWGameDetailsViewController *gameDetails = [[HWGameDetailsViewController alloc]init];
//          gameDetails.gameId = model.gid;
//          [self.navigationController pushViewController:gameDetails animated:YES];
//        return;
//
//    }
    
    NSLog(@"ioohuhuh");
    
  //   self.slideArr
    
      NSDictionary *dic =    self.slideArr[index];
      HWGameDetailController *gameDetails = [[HWGameDetailController alloc]init];
      gameDetails.gameId = dic[@"gid"];
      [self.navigationController pushViewController:gameDetails animated:YES];
            
    
    NSLog(@"%@",dic);
    
    
    
}




@end


